package com.hh.service.service.impl.im;

import com.hh.common.constants.ImConstants;
import com.hh.common.utils.RedisUtil;
import com.tencentyun.TLSSigAPIv2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;


public class BaseImService {

    @Autowired
    private RedisUtil redisUtil;

    @Value("${IMConfig.sdkAppId}")
    private long sdkAppId;
    @Value("${IMConfig.secretKey}")
    private String secretKey;
    @Value("${IMConfig.identifier}")
    private String identifier;

    private long expire = 604800;

    public long getSdkAppId() {
        return sdkAppId;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public String getIdentifier() {
        return identifier;
    }

    public long getExpire() {
        return expire;
    }

    public String getAdminUserSig(String userId){
        String o = redisUtil.get(ImConstants.IMADMINUSERSIGCACHEKEY);
        if(o != null){
            return o;
        }else {
            TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(getSdkAppId(), getSecretKey());
            String sig = tlsSigAPIv2.genUserSig(userId, expire);
            redisUtil.set(ImConstants.IMADMINUSERSIGCACHEKEY,sig,expire);
            return sig;
        }
    }

}
